package sms;

public class SMSDetails 
{
	public boolean ERROR=false;
	String data; 
	String status;
	String mobileNumber;
	String date;
	public void generate(String message, String modelName)
	{
		 if(message.indexOf("ERROR") != -1 || message.indexOf(':') <= 0)
		 {
		        ERROR = false;
		        return;
		 }
		int startOfMessage = message.indexOf("\r", message.indexOf(":") + 1) + 2;
	    int endOfMessage = message.length();
	    if(modelName.equals("HUAWEI"))
	    {
	        startOfMessage = message.indexOf("\r", message.indexOf(":") + 1) + 2;
	        System.out.println((new StringBuilder()).append("start Of Message : ").append(startOfMessage).toString());
	        endOfMessage = message.length();
	        System.out.println((new StringBuilder()).append("end Of Message : ").append(endOfMessage).toString());
	    }
	    if(endOfMessage - 8 < 25)
	    {
	        ERROR = false;
	        return;
	    }
	
		if(modelName.equals("HUAWEI"))
        {
            data = message.substring(startOfMessage, endOfMessage - 8);
            System.out.println((new StringBuilder()).append("SMS is : ").append(data).toString());
            int start = message.indexOf(',');
            date = message.substring(start+1, message.indexOf(',',start+1));
            date = date.replace("<", "");
            date = date.replace("/", "-");
            date = date.replace(">", "");
            status = message.substring(message.indexOf(':') + 1, message.indexOf(','));
            status = status.trim();
            status = status.substring(1, status.length() - 1);
            System.out.println((new StringBuilder()).append("The status is : ").append(status).toString());
            mobileNumber = message.substring(message.indexOf(':') + 1, message.indexOf(','));
            mobileNumber = mobileNumber.trim();
            System.out.println((new StringBuilder()).append("Mobile Number is : ").append(mobileNumber).toString());
        }
        ERROR = true;
	}
	public boolean getError()
	{
		return ERROR;
	}
	
	public String getData() {
		return data;
	}
	
	public String getNumber()
	{
		if(mobileNumber.indexOf("0")==0)
		{
			mobileNumber = "+91"+mobileNumber.substring(1);
		}
		return mobileNumber;
	}
	
	public String getDate() {
		return date;
	}
	
	public String getStatus() {
		return status;
	}
}
